package com.xyht.sca_s.student_manage_system.modules.teacher.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.teacher.entity.req.SmsTeacherAwardAddReq;
import com.xyht.sca_s.student_manage_system.modules.teacher.entity.req.SmsTeacherAwardDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.teacher.service.SmsTeacherAwardService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * <p>
 * 教师获奖信息表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-09-05
 */
@RestController
@RequestMapping("/teacherAward")
@SecretBody
public class SmsTeacherAwardController {


    @Resource
    private SmsTeacherAwardService smsTeacherAwardService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "招生信息批量导入")
    @PostMapping("/batch/add")
    public ResponseResult batchAddEnrolStudent(@RequestBody Map<String,Object> map, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = smsTeacherAwardService.batchAddTeacherAward(map,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiModelProperty("新增教师获奖")
    @PostMapping("/add")
    public ResponseResult addTeacherAward(@RequestBody SmsTeacherAwardAddReq addReq){
        return smsTeacherAwardService.addTeacherAward(addReq);
    }

    @ApiModelProperty("查看教师获奖")
    @GetMapping("/get")
    public ResponseResult getTeacherAward(@RequestParam(value = "id",required = false) String id){
        return smsTeacherAwardService.getTeacherAward(id);
    }


    @ApiModelProperty("删除教师获奖")
    @PostMapping("/deleted")
    public ResponseResult deletedTeacherAward(@RequestBody SmsTeacherAwardDeletedReq deletedReq){
        return smsTeacherAwardService.deletedTeacherAward(deletedReq);
    }


    @ApiModelProperty("查看教师获奖列表")
    @GetMapping("/list")
    public ResponseResult getTeacherAwardList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                              @RequestParam(value = "tchName",required = false) String tchName,
                                              @RequestParam(value = "awardGrade",required = false) String awardGrade,
                                              @RequestParam(value = "awardName",required = false) String awardName){
        return smsTeacherAwardService.getTeacherAwardList(pageNum,pageSize,tchName,awardGrade,awardName);
    }

}

